//
//  ljdrawrect.m
//  saasRetail
//
//  Created by mac on 2022/10/27.
//

#import "ljdrawrect.h"

@interface ljdrawrect () {
    CGPoint _startpoint;
    CGPoint _middlepoint;
    CGPoint _endpoint;
    UIColor *_color;
}
@end

@implementation ljdrawrect

#pragma mark - method
- (instancetype)initStartPoint:(CGPoint)startpoint middlepoint:(CGPoint)middlepoint endpoint:(CGPoint) endpoint color:(UIColor*)color
{
    if (self = [super init]) {
        _startpoint = startpoint;
        _middlepoint = middlepoint;
        _endpoint = endpoint;
        _color = color;
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextBeginPath(context);//标记
    CGContextMoveToPoint(context, _startpoint.x, _startpoint.y);
    CGContextAddLineToPoint(context,_middlepoint.x, _middlepoint.y);
    CGContextAddLineToPoint(context,_endpoint.x, _endpoint.y);
    CGContextClosePath(context);//路径结束标志，不写默认封闭
    [_color setFill]; //设置填充色
    [_color setStroke];//边框也设置为_color，否则为默认的黑色
    CGContextDrawPath(context, kCGPathFillStroke);//绘制路径path
}

@end
